<template>
  <!-- 机构管理 -->
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :model="form" label-width="150px" :inline="true">
        <el-row>
          <el-col :span="8">
            <el-form-item label="机构名称">
              <el-input v-model="form.keyword" clearable @keyup.enter.native="handleSearch"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="机构手机号">
              <el-input v-model="form.org_phone" clearable @keyup.enter.native="handleSearch"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入驻日期" width="236">
              <el-date-picker
                v-model="time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6" style="float:right">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
              <!-- <Exprotcomponent :params="form" url="admin/ticket_export" type="php"></Exprotcomponent> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="listDiv" v-loading="tableLoading">
      <el-table ref="tableData" :data="tableData" style="width: 100%">
        <el-table-column
          fixed
          type="index"
          label="编号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="机构名称" prop="hospital_name" align="center" width="150px" />
        <el-table-column label="机构所属版块" prop="module_name" align="center">
        </el-table-column>
        <el-table-column label="机构所属城市" prop="city" align="center">
          <template slot-scope="scope"><span>{{scope.row.province_name}}</span> <span v-if="scope.row.city_name">-{{scope.row.city_name}}</span></template>
        </el-table-column>
        <el-table-column label="机构负责人姓名" prop="org_realname" align="center" />
        <el-table-column label="机构负责人手机号" prop="org_phone" align="center">
        </el-table-column>

        <el-table-column label="回款比率" prop="return_ratio" align="center">
        </el-table-column>
        <!-- 结算模式 固定为1 预存款模式 -->
        <el-table-column label="结算模式" prop="settle_mode_name" align="center">
        </el-table-column>
        <el-table-column label="关联城市合伙人" prop="realname" align="center" />
        <el-table-column label="城市合伙人手机号" prop="phone" align="center" />

        <el-table-column label="城市合伙人签约时间" prop="partner_signtime" align="center" width="200px">
          <!-- <template slot-scope="scope">
            <span>{{(scope.row.created_at - 0 ) / 1000 | date(1)}}</span>
          </template>-->
        </el-table-column>
        <el-table-column label="机构签约时间" prop="org_signtime" align="center" width="200px">
          <!-- <template slot-scope="scope">
            <span>{{(scope.row.created_at - 0 ) / 1000 | date(1)}}</span>
          </template>-->
        </el-table-column>
        <el-table-column label="备注" prop="remark" align="center" />

        <el-table-column label="操作" fixed="right" align="center" prop="opt">
          <template slot-scope="scope">
            {{scope.row.is_On}}
            <el-switch
              v-model="scope.row.is_on"
              @change="switchChange(scope.row.id,scope.row.is_on)"
              :active-value="1"
              :inactive-value="2"
            ></el-switch>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
// import { couponsList, useScope, getNum, isOn } from "@/api/quanMange";
// import commonFn from "@/utils/common";
// import filter from "@/assets/filter";
import {org_index,org_onsale} from "@/api/NewRetailSystem"

export default {
  name: "organizationalManagement",
  data() {
    return {
      form: {
        keyword: "",
        page: 1,
        size: 10
      },
      form1: {
        page: 1,
        pagesize: 10
      },
      page_sizes: [10, 30, 50, 100],
      page_totals: 0,
      tableData: [{}],
      tableLoading: false,
      dialogFormVisible: false,
      time: null,
    };
  },
  watch: {
    time(val) {
      if (val) {
        this.form.created_at = val[0] + " - " + val[1];
      } else {
        this.form.created_at = "";
      }
    }
  },
  filters: {
    // 时间戳转化
    dates(opt) {
      if (opt) {
        // yyyy-MM-dd hh:mm:ss
        return new Date(Number(opt) * 1000).format("yyyy-MM-dd");
      } else {
        return "--";
      }
    }
  },
  mounted() {
    this.getList(this.form);
  },
  methods: {
    //   路由跳转
    toRoutes(name) {
      let routes = { name };
      this.$router.push(routes);
    },
    // 编号
    table_index(index) {
      return (this.form.page - 1) * this.form.size + index + 1;
    },
    //列表
    async getList(opt) {
      let res = await org_index(opt);
      if (res.data.code == 200) {
        this.tableLoading = false;
        this.tableData = res.data.data;
        this.page_totals = res.data.meta.total;
      } else {
        this.tableLoading = false;
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
      }
    },
    // 下架
    switchChange(id,opt) {
      let data = { id:id,opt:opt };
      org_onsale(data).then(res => {
        if (res.data.code == 200) {
          this.$message({
            message: "修改成功",
            type: "success"
          });
        } else {
          this.$message({
            message: res.data.msg,
            type: "warning"
          });
        }
        this.getList(this.form);
      });
    },
    //   查询
    handleSearch() {
      this.form.page = 1;
      this.getList(this.form);
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.size = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form);
    },
  }
};
</script>
<style scoped>
.app-container {
  padding: 0px !important;
  background: transparent;
}
.formDiv{
  padding: 20px;
}
/* 主页列表样式 */
.listDiv {
  margin-bottom: 20px;
  padding: 0 20px;
}
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.pagesCon {
  text-align: right;
  margin-top: 20px;
}
</style>